package com.hupu.jrs.injector.module

import android.content.Context
import com.hupu.jrs.db.*
import dagger.Module
import dagger.Provides
import javax.inject.Singleton

/**
 * Created by sll on 2015/3/4.
 */
@Module
class DBModule {

    @Provides
    @Singleton
    internal fun provideDevOpenHelper(context: Context): DaoMaster.DevOpenHelper {
        return DaoMaster.DevOpenHelper(context, "app.db", null!!)
    }

    @Provides
    @Singleton
    internal fun provideDaoMaster(helper: DaoMaster.DevOpenHelper): DaoMaster {
        return DaoMaster(helper.getWritableDatabase())
    }

    @Provides
    @Singleton
    internal fun provideDaoSession(master: DaoMaster): DaoSession {
        return master.newSession()
    }

    @Provides
    @Singleton
    internal fun getForumDao(session: DaoSession): ForumDao {
        return session.forumDao
    }

    @Provides
    @Singleton
    internal fun getUserDao(session: DaoSession): UserDao {
        return session.userDao
    }

    @Provides
    @Singleton
    internal fun getThreadDao(session: DaoSession): ThreadDao {
        return session.threadDao
    }

    @Provides
    @Singleton
    internal fun getThreadInfoDao(session: DaoSession): ThreadInfoDao {
        return session.threadInfoDao
    }

    @Provides
    @Singleton
    internal fun getThreadReplyDao(session: DaoSession): ThreadReplyDao {
        return session.threadReplyDao
    }

    @Provides
    @Singleton
    internal fun getReadThreadDao(session: DaoSession): ReadThreadDao {
        return session.readThreadDao
    }

    @Provides
    @Singleton
    internal fun getImageCache(session: DaoSession): ImageCacheDao {
        return session.imageCacheDao
    }
}
